package com.ruoyi.mdkt.controller;

import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.uuid.UUID;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * 文件上传控制器
 */
@CrossOrigin

@RestController
@RequestMapping("/mdkt/upload")
public class FileUploadController {
    @Value("${qiniu.ak}")
    private String accessKey;
    @Value("${qiniu.sk}")
    private String secretKey;
    @Value("${qiniu.bucket}")
    private String bucket;
    @GetMapping("/getToken")
    public R getToken() {
        String key = UUID.randomUUID().toString()+System.currentTimeMillis();
        Configuration cfg = new Configuration(Region.region1());
        Auth auth = Auth.create(accessKey, secretKey);
        String upToken = auth.uploadToken(bucket,key);
        return R.ok(upToken);
    }

    @PostMapping("/upload")
    public R uploadMsg(@RequestParam("key") String key, @RequestParam("hash") String hash) {
        String url = "";
        return R.ok(url);
    }
}
